package com.AFH.test;

import java.lang.reflect.InvocationTargetException;

public class AttackRunningThread extends Thread {

	boolean flag = false;
	boolean spStart = false;
	int tmp = 0;
	AttackThread at;
	public AttackRunningThread(AttackThread at){
		super.setName("AttackThread");
		this.at=at;
	}

	@Override
	public void run() {
		while (flag) {
			while (spStart) {
				try {
					if (!at.sp.st.isAlive()) {
						spStart=false;
						flag = false;
					} else if ((!(Boolean) at.method2.invoke(at.ob)) && (tmp == 0)) {
						at.currentFrame = 0;
						at.method1.invoke(at.ob, at.attack);
						// method3.invoke(ob, 2);
					} else if ((Boolean) at.method2.invoke(at.ob)) {
						// method3.invoke(ob,0);

						at.stopAttack();
					}

					tmp = (tmp + 100) % at.sleepSpan;
					at.nextframe();
					Thread.sleep(100);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
}
